package service.impl;

import dao.UserMapper;
import entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import service.UserService;

import java.util.List;

@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userDao;


    @Override
    public void add(User user) {
        userDao.insert(user);
        int i=1/0;
    }

    @Override
    public void remove(Integer id) {
        userDao.deleteByPrimaryKey(id);
    }

    @Override
    public void modify(User user) {
        userDao.updateByPrimaryKey(user);
    }

    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    @Override
    public User findById(Integer id) {
        return userDao.selectByPrimaryKey(id);
    }

    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    @Override
    public List<User> findAll() {
        return userDao.selectAll();
    }


    public UserMapper getUserDao() {
        return userDao;
    }

    public void setUserDao(UserMapper userDao) {
        this.userDao = userDao;
    }
}
